<template>
  <div class="app-container">
    <el-tabs
      v-model="activeTab"
      style="
        position: absolute;
        width: 100%;
        height: 553px;
        top: 0%;
        left: 0.159744%;
        text-align: left;
      "
      :tab-position="tabPosition"
      stretch
      @tab-click="handleClick"
    >
      <el-tab-pane name="first" style="height: 474px" label="基本信息">
        <!--按钮-->
        <el-row
          :gutter="10"
          class="mb8"
          style="
            height: 50px;
            width: 100%;
            display: flex;
            justify-content: right;
          "
        >
          <!-- <el-col :span="1.5">
            <el-button
              type="primary"
              plain
              icon="el-icon-plus"
              size="mini"
              @click="handleAdd"
              v-hasPermi="['teacher:person:add']"
              >新增</el-button
            >
          </el-col> -->
          <!-- 确定按钮 -->
          <el-col :span="1.5">
            <el-button
              size="mini"
              v-show="hidden"
              type="primary"
              @click="submitForm"
            >
              确 定
            </el-button>
          </el-col>
          <!-- 取消按钮 -->
          <el-col :span="1.5">
            <el-button size="mini" v-show="hidden" @click="cancel">
              取 消
            </el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              v-show="hidden"
              type="success"
              plain
              icon="el-icon-success"
              size="mini"
              @click="handleAdd"
              v-hasPermi="['teacher:person:add']"
            >保存</el-button
            >
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="info"
              plain
              icon="el-icon-circle-close"
              size="mini"
              @click="revoke"
            >撤销</el-button
            >
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="warning"
              plain
              icon="el-icon-edit"
              size="mini"
              @click="handleUpdate"
              v-hasPermi="['teacher:person:edit']"
            >修改</el-button
            >
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="danger"
              plain
              icon="el-icon-delete"
              size="mini"
              @click="reset"
            >清空</el-button
            >
          </el-col>
          <!-- <el-col :span="1.5">
            <el-button
              type="danger"
              plain
              icon="el-icon-delete"
              size="mini"
              :disabled="multiple"
              @click="handleDelete"
              v-hasPermi="['teacher:person:remove']"
              >删除</el-button
            >
          </el-col> -->
          <el-col :span="1.5">
            <el-button
              type="warning"
              plain
              icon="el-icon-download"
              size="mini"
              @click="handleExport"
              v-hasPermi="['teacher:person:export']"
            >导出</el-button
            >
          </el-col>
          <!-- <right-toolbar
            :showSearch.sync="showSearch"
            @queryTable="getList"
          ></right-toolbar> -->
        </el-row>
        <el-form
          :model="queryParams"
          ref="queryForm"
          :inline="true"
          v-show="showSearch"
          label-width="68px"
          style="height: 500px"
        >
          <el-form ref="form" :model="form" :rules="rules" label-width="100px">
            <el-form-item label="照片">
              <imageUpload v-model="form.zdyxa0106" />
            </el-form-item>
            <el-form-item label="姓名" prop="a0101">
              <el-input
                v-show="hidden"
                v-model="form.a0101"
                placeholder="请输入姓名"
                style="width: 220px"
              />
              <div v-show="!hidden">{{ form.a0101 }}</div>
            </el-form-item>
            <el-form-item label="用户ID" prop="userId">
              <el-input
                v-show="hidden"
                v-model="form.userId"
                placeholder="请输入用户ID"
                style="width: 220px"
              />
              <div v-show="!hidden">{{ form.userId }}</div>
            </el-form-item>
            <el-form-item label="教师编号" prop="a0199">
              <el-input
                v-show="hidden"
                v-model="form.a0199"
                placeholder="请输入教师编号"
                style="width: 220px"
              />
              <div v-show="!hidden">{{ form.a0199 }}</div>
            </el-form-item>
            <el-form-item label="性别" prop="a0104">
              <el-select
                v-show="hidden"
                v-model="form.a0104"
                placeholder="请选择性别"
              >
                <el-option
                  v-for="dict in a0104Options"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
              <div v-show="!hidden">{{ form.a0104 }}</div>
            </el-form-item>
            <el-form-item label="出生日期" prop="a0107">
              <el-date-picker
                v-show="hidden"
                clearable
                size="small"
                v-model="form.a0107"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="选择出生日期"
              >
              </el-date-picker>
              <div v-show="!hidden">{{ form.a0107 }}</div>
            </el-form-item>
            <el-form-item label="籍贯" prop="a0111b">
              <el-select
                v-show="hidden"
                v-model="form.a0111b"
                placeholder="请选择籍贯"
                filterable
              >
                <el-option
                  v-for="dict in a0111bOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
              <div v-show="!hidden">{{ form.zdyxa01110 }}</div>
            </el-form-item>
            <el-form-item label="出生地" prop="a0114b">
              <el-select
                v-show="hidden"
                v-model="form.a0114b"
                placeholder="请选择出生地"
                filterable
              >
                <el-option
                  v-for="dict in a0114bOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
              <div v-show="!hidden">{{ form.a0114b }}</div>
            </el-form-item>
            <el-form-item label="民族" prop="a0117">
              <el-select
                v-show="hidden"
                v-model="form.a0117"
                placeholder="请选择民族"
                filterable
              >
                <el-option
                  v-for="dict in a0117Options"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
              <div v-show="!hidden">{{ form.a0117 }}</div>
            </el-form-item>
            <el-form-item label="健康状况" prop="a0127">
              <el-select
                v-show="hidden"
                v-model="form.a0127"
                placeholder="请选择健康状况"
              >
                <el-option
                  v-for="dict in a0127Options"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
              <div v-show="!hidden">{{ form.a0127 }}</div>
            </el-form-item>
            <el-form-item label="婚姻状况" prop="a0131">
              <el-select
                v-show="hidden"
                v-model="form.a0131"
                placeholder="请选择婚姻状况"
              >
                <el-option
                  v-for="dict in a0131Options"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
              <div v-show="!hidden">{{ form.a0131 }}</div>
            </el-form-item>

            <el-form-item label="政治面貌" prop="a0141">
              <el-select
                v-show="hidden"
                v-model="form.a0141"
                placeholder="请选择政治面貌"
              >
                <el-option
                  v-for="dict in a0141Options"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
              <div v-show="!hidden">{{ form.a0141 }}</div>
            </el-form-item>
            <el-form-item label="户籍所在地" prop="a0181a">
              <el-select
                v-show="hidden"
                v-model="form.a0181a"
                placeholder="请选择户籍所在地"
                filterable
              >
                <el-option
                  v-for="dict in a0181aOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
              <div v-show="!hidden">{{ form.a0181a }}</div>
            </el-form-item>
            <el-form-item label="有效证件类别" prop="a0183">
              <el-select
                v-show="hidden"
                v-model="form.a0183"
                placeholder="请选择有效证件类别"
              >
                <el-option
                  v-for="dict in a0183Options"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
              <div v-show="!hidden">{{ form.a0183 }}</div>
            </el-form-item>
            <el-form-item label="身份证号" prop="a0184">
              <el-input
                v-show="hidden"
                v-model="form.a0184"
                placeholder="请输入身份证号"
                style="width: 220px"
              />
              <div v-show="!hidden">{{ form.a0184 }}</div>
            </el-form-item>
            <el-form-item label="删除标识" prop="delFlag">
              <el-input
                v-show="hidden"
                v-model="form.delFlag"
                placeholder="请输入删除标识"
                style="width: 220px"
              />
              <div v-show="!hidden">{{ form.delFlag }}</div>
            </el-form-item>

            <el-form-item label="人员现状" prop="zdyxa0109">
              <el-input
                v-show="hidden"
                v-model="form.zdyxa0109"
                placeholder="请输入人员现状"
                style="width: 220px"
              />
              <div v-show="!hidden">{{ form.zdyxa0109 }}</div>
            </el-form-item>
            <el-form-item label="进入本校时间" prop="zdyxa01110">
              <el-date-picker
                v-show="hidden"
                clearable
                size="small"
                v-model="form.zdyxa01110"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="选择进入本校时间"
              >
              </el-date-picker>
              <div v-show="!hidden">{{ form.zdyxa01110 }}</div>
            </el-form-item>
            <el-form-item label="参加工作日期" prop="a0134" height="36px">
              <el-date-picker
                v-show="hidden"
                clearable
                size="small"
                v-model="form.a0134"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="选择参加工作日期"
              >
              </el-date-picker>
              <div v-show="!hidden">{{ form.a0134 }}</div>
            </el-form-item>
            <el-form-item label="备注" prop="remark" style="width: 100%">
              <el-input
                v-show="hidden"
                v-model="form.remark"
                type="textarea"
                placeholder="请输入内容"
                style="width: 220px"
              />
              <div v-show="!hidden">{{ form.remark }}</div>
            </el-form-item>
          </el-form>
        </el-form>
      </el-tab-pane>
      <el-tab-pane
        name="second"
        style="height: 474px"
        label="教育背景"
      ></el-tab-pane>
      <el-tab-pane
        name="three"
        style="height: 475px"
        label="工作经历"
      ></el-tab-pane>
      <el-tab-pane
        name="four"
        style="height: 473px"
        label="职称信息"
      ></el-tab-pane>
      <el-tab-pane
        name="five"
        style="height: 472px"
        label="年度考核"
      ></el-tab-pane>
      <el-tab-pane
        name="six"
        style="height: 472px"
        label="培训情况"
      ></el-tab-pane>
      <el-tab-pane
        name="seven"
        style="height: 472px"
        label="档案信息"
      ></el-tab-pane>
      <el-tab-pane
        name="eight"
        style="height: 472px"
        label="附件材料"
      ></el-tab-pane>
    </el-tabs>
    <!--分页-->
    <!-- <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        /> -->

    <!-- 添加或修改教师基本信息对话框 -->
    <!--    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>-->

    <!--      <div slot="footer" class="dialog-footer">-->
    <!--        <el-button type="primary" @click="submitForm">确 定</el-button>-->
    <!--        <el-button @click="cancel">取 消</el-button>-->
    <!--      </div>-->
    <!--    </el-dialog>-->
  </div>
</template>

<script>
import {
  getTeacherInfo,
  listPerson,
  getPerson,
  delPerson,
  addPerson,
  updatePerson,
  exportPerson,
} from "@/api/teacher/person";
import ImageUpload from "@/components/ImageUpload";

export default {
  name: "Person",
  components: {
    ImageUpload,
  },
  data() {
    return {
      hidden: false,
      activeTab: "first",
      tabPosition: "top",
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 教师基本信息表格数据
      personList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 性别字典
      a0104Options: [],
      // 籍贯字典
      a0111bOptions: [],
      // 出生地字典
      a0114bOptions: [],
      // 民族字典
      a0117Options: [],
      // 健康状况字典
      a0127Options: [],
      // 婚姻状况字典
      a0131Options: [],
      // 政治面貌字典
      a0141Options: [],
      // 户籍所在地字典
      a0181aOptions: [],
      // 有效证件类别字典
      a0183Options: [],
      // 查询参数
      queryParams: {
        // pageNum: 1,
        // pageSize: 10,
        // userId: 115,
        a0101: null,
        a0104: null,
        a0141: null,
        a0199: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        a00: [
          { required: true, message: "人员标识符不能为空", trigger: "blur" },
        ],
        a0101: [{ required: true, message: "姓名不能为空", trigger: "blur" }],
      },
    };
  },
  created() {
    console.log(this.$route.query);
    this.userId = this.$route.query.userId;
    // this.getList();
    this.getTeacherInfo(this.userId);
    this.getDicts("sys_user_sex").then((response) => {
      this.a0104Options = response.data;
    });
    this.getDicts("sys_person_place").then((response) => {
      this.a0111bOptions = response.data;
    });
    this.getDicts("sys_person_place").then((response) => {
      this.a0114bOptions = response.data;
    });
    this.getDicts("sys_person_nationality").then((response) => {
      this.a0117Options = response.data;
    });
    this.getDicts("sys_person_health").then((response) => {
      this.a0127Options = response.data;
    });
    this.getDicts("sys_person_marry").then((response) => {
      this.a0131Options = response.data;
    });
    this.getDicts("sys_person_landscape").then((response) => {
      this.a0141Options = response.data;
    });
    this.getDicts("sys_person_place").then((response) => {
      this.a0181aOptions = response.data;
    });
    this.getDicts("sys_person_card").then((response) => {
      this.a0183Options = response.data;
    });
  },
  methods: {
    /** 查询教师基本信息列表 */
    // getList () {
    //   this.loading = true;
    //   listPerson(this.queryParams).then(response => {
    //     this.personList = response.rows;
    //     this.total = response.total;
    //     this.loading = false;
    //   });
    // },
    handleClick() {
      console.log('111');
      this.getTeacherInfo();
    },
    //通过userId获取教师基本信息
    getTeacherInfo() {
      getTeacherInfo(this.userId).then((response) => {
        this.form = response.data;
        this.total = response.total;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 撤销按钮
    revoke() {
      this.hidden = false;
      this.open = false;
    },
    // 表单重置
    reset() {
      this.hidden = false;
      this.form = {
        a00: null,
        a0101: null,
        userId: null,
        a0104: null,
        a0107: null,
        a0111b: null,
        a0114b: null,
        a0117: null,
        a0127: null,
        a0131: null,
        a0134: null,
        a0141: null,
        a0181a: null,
        a0183: null,
        a0184: null,
        a0199: null,
        zdyxa0106: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        delFlag: null,
        remark: null,
        zdyxa0109: null,
        zdyxa01110: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.a00);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd () {
      this.reset();
      this.open = true;
      this.title = "添加教师基本信息";
    },
    /** 修改按钮操作 */
    handleRevoke() {
      this.xiugaibasic = false;
    },
    handleUpdate(row) {
      // this.reset();取消清空表单
      this.hidden = true;
      const a00 = row.a00 || this.ids;
      getPerson(a00).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改教师基本信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.a00 != null) {
            updatePerson(this.form).then((response) => {
              this.loading = true;
              this.msgSuccess("修改成功");
              this.hidden = false;
              this.open = false;
              this.getList();
            });
          } else {
            addPerson(this.form).then((response) => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
      // setTimeout(() => {
      //   this.revoke();
      // }, 3000);
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const a00s = row.a00 || this.ids;
      this.$confirm(
        '是否确认删除教师基本信息编号为"' + a00s + '"的数据项?',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(function () {
          return delPerson(a00s);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        });
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm("是否确认导出所有教师基本信息数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return exportPerson(queryParams);
        })
        .then((response) => {
          this.download(response.msg);
        });
    },
  },
};
</script>
<style>
::v-deep .el-tabs__nav-scroll {
  width: 50% !important;
  margin: 0 auto !important;
}
.el-form--inline .el-form-item {
  width: 31%;
  float: left;
}
.el-form-item--medium .el-form-item__content {
  margin-left: 30px !important;
}
</style>
